broadway: Fix flicker when resizing windows
authorAlexander Larsson <alexl@redhat.com>
Tue, 15 Mar 2011 09:18:07 +0000 (10:18 +0100)
committerAlexander Larsson <alexl@redhat.com>
Tue, 15 Mar 2011 09:18:07 +0000 (10:18 +0100)
Resizing a canvas causes a clear, so we have to save the previous
content and restore to avoid flickering.

gdk/broadway/broadway.js

index 89242e353ab329c2237fb637c8632ea5b174eaf5..286f0de7feef533ce371155f3d0ef546363b40db 100644 (file)
@@ -276,10 +276,26 @@ function handleCommands(cmd_obj)
         i = i + 3;
         var h = base64_16(cmd, i);
         i = i + 3;
-       flushSurface(surfaces[id]);
-       surfaces[id].canvas.width = w;
-       surfaces[id].canvas.height = h;
-        break;
+       var surface = surfaces[id];
+
+       /* Flush any outstanding draw ops before changing size */
+       flushSurface(surface);
+
+       /* Canvas resize clears the data, so we need to save it first */
+       var tmpCanvas = document.createElement("canvas");
+       tmpCanvas.width = surface.canvas.width;
+       tmpCanvas.height = surface.canvas.height;
+       var tmpContext = tmpCanvas.getContext("2d");
+       tmpContext.globalCompositeOperation = "copy";
+       tmpContext.drawImage(surface.canvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
+
+       surface.canvas.width = w;
+       surface.canvas.height = h;
+
+       surface.globalCompositeOperation = "copy";
+       surface.drawImage(tmpCanvas, 0, 0, tmpCanvas.width, tmpCanvas.height);
+
+       break;
 
       /* put image data surface */
       case 'i':